#pragma once

#include <string>
#include <unordered_map>
#include <iostream>
#include <fstream>

static const std::string sep = ": ";

class Dict
{
private:
    void LoadDict(const std::string& path)
    {
        std::fstream in(path);

        std::string line;
        while(std::getline(in, line))
        {
            if(line.empty()) continue;
            size_t pos = line.find(sep);
            if(pos == std::string::npos) continue;
            std::string key = line.substr(0, pos);
            if(key.empty()) continue;
            std::string value = line.substr(pos+sep.size());
            if(value.empty()) continue;

            _dict.insert(std::make_pair(key, value));
        }
        in.close();
    }
public:
    Dict(const std::string& path) :_dict_path(path)
    {
        LoadDict(_dict_path);
    }

    const std::string Translate(const std::string& key)
    {
        if(key.empty()) return "None";
        auto iter = _dict.find(key);
        if(iter == _dict.end()) return "None";
        return iter->second;
    }
private:
    std::unordered_map<std::string, std::string> _dict;
    std::string _dict_path;
};